package org.ioc.com.book7.service;

import org.ioc.com.book7.enums.BookStatus;
import org.ioc.com.book7.mapper.BookInfoMapper;
import org.ioc.com.book7.model.BookInfo;
import org.ioc.com.book7.model.PageRequest;
import org.ioc.com.book7.model.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class BookInfoService {
    @Autowired
    private BookInfoMapper bookInfoMapper;
    public Integer insert(BookInfo bookInfo) {
        Integer integer=bookInfoMapper.queryInsert(bookInfo);
        return integer;
    }

    public PageResult<BookInfo> select(PageRequest pageRequest) {
        List<BookInfo> bookInfos=bookInfoMapper.querySelect(pageRequest.getOffset(),pageRequest.getPageSize());
        Integer count = bookInfoMapper.count();
        for (BookInfo bookInfo:bookInfos){
            bookInfo.setStatusCn(BookStatus.getByCode(bookInfo.getStatus()));
        }
        return new PageResult<>(bookInfos,count);
    }

    public BookInfo selectOne(Integer id) {
        BookInfo bookInfo=bookInfoMapper.querySelectOne(id);
        return bookInfo;
    }

    public Integer update(BookInfo bookInfo) {
        Integer up=bookInfoMapper.queryUpdate(bookInfo);
        return up;
    }

    public Integer delete(Integer id) {
        Integer delete=bookInfoMapper.queryDelete(id);
        return delete;
    }

    public Integer batchDelete(List<Integer> ids) {
        Integer batch=bookInfoMapper.queryBatchDelete(ids);
        return batch;
    }
}
